﻿/*
 * RegExpress
 * 
 * Copyright (c) 2010, Daniel McGaughran
 * 
 * Licensed under the Apache Licence, Version 2.0 (the "Licence");
 * you may not use this file except in compliance with the Licence.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Licence is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and
 * limitations under the Licence.
 * 
 */

using System;
using System.Collections.Generic;
using RegExpressModel.Entities;


namespace RegExpressViewModel
{
	class SlideViewModelFactory
	{
		private static Dictionary<SlideType, Func<Slide, SlideViewModel>> _generator;


		static SlideViewModelFactory()
		{
			_generator = new Dictionary<SlideType, Func<Slide, SlideViewModel>>();
			_generator.Add(SlideType.Title, CreateTitleSlide);
			_generator.Add(SlideType.NavMap, CreateNullObject);
			_generator.Add(SlideType.Image, CreateImageSlide);
			_generator.Add(SlideType.FixedContent, CreateFixedContentSlide);
			_generator.Add(SlideType.SourceCode, CreateSourceCodeSlide);
			_generator.Add(SlideType.BasicMatch, CreateBasicMatchSlide);
			_generator.Add(SlideType.MultiMatch, CreateMultiMatchSlide);
			_generator.Add(SlideType.FindMatches, CreateFindMatchesSlide);
			_generator.Add(SlideType.ReplaceMatches, CreateReplaceMatchesSlide);
		}



		public static SlideViewModel CreateFrom(Slide source)
		{
			if (source == null) return null;

			return _generator[source.Type](source);
		}


		private static SlideViewModel CreateTitleSlide(Slide source)
		{
			return new TitleSlideViewModel((TitleSlide)source);
		}

		private static SlideViewModel CreateImageSlide(Slide source)
		{
			return new ImageSlideViewModel((ImageSlide)source);
		}

		private static SlideViewModel CreateSourceCodeSlide(Slide source)
		{
			return new SourceCodeSlideViewModel((SourceCodeSlide)source);
		}

		private static SlideViewModel CreateFixedContentSlide(Slide source)
		{
			return new FixedContentSlideViewModel((FixedContentSlide)source);
		}

		private static SlideViewModel CreateBasicMatchSlide(Slide source)
		{
			return new BasicMatchSlideViewModel((BasicMatchSlide)source);
		}

		private static SlideViewModel CreateMultiMatchSlide(Slide source)
		{
			return new MultiMatchSlideViewModel((MultiMatchSlide)source);
		}

		private static SlideViewModel CreateFindMatchesSlide(Slide source)
		{
			return new FindMatchesSlideViewModel((FindMatchesSlide)source);
		}

		private static SlideViewModel CreateReplaceMatchesSlide(Slide source)
		{
			return new ReplaceMatchesSlideViewModel((ReplaceMatchesSlide)source);
		}


		private static SlideViewModel CreateNullObject(Slide source)
		{
			return null;
		}


	}
}
